﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Qiang.Styles
{
    public class SimpleLineStyle:LineStyle,ISimpleLineStyle
    {

        #region 初始化

        /// <summary>
        /// 
        /// </summary>
        public SimpleLineStyle()
        {
            _color = Color.FromArgb(255, Random.Next(0, 255), Random.Next(0, 255), Random.Next(0, 255));
            _width = 1.0;
            _dashStyle = DashStyle.Dash;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="color"></param>
        /// <param name="width"></param>
        public SimpleLineStyle(Color color, double width)
        {
            _color = color;
            _width = (float)width;
            _dashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        }

        #endregion


        #region 属性

        /// <summary>
        /// 样式类型。
        /// </summary>
        public override LineStyleType StyleType
        {
            get { return LineStyleType.Simple; }
        }


        Color _color;

        /// <summary>
        /// 颜色。
        /// </summary>
        public Color Color
        {
            get { return _color; }
            set { _color = value; }
        }

        DashStyle _dashStyle;

        /// <summary>
        /// 虚线绘制样式。
        /// </summary>
        public DashStyle DashStyle
        {
            get { return _dashStyle; }
            set { _dashStyle = value; }
        }


        double _width;

        /// <summary>
        /// 线宽。
        /// </summary>
        public double Width
        {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// 透明度。
        /// </summary>
        public override float Opacity
        {
            get
            {
                return _color.A / 255f;
            }
            set
            {
                float val = value;
                if (val > 1) val = 1f;
                if (val < 0) val = 0f;
                _color = Color.FromArgb((int)val * 255, _color);
            }
        }



        #endregion


        #region 方法

        /// <summary>
        /// 绘制。
        /// </summary>
        /// <param name="g"></param>
        /// <param name="path"></param>
        public override void DrawPath(Graphics g, GraphicsPath path)
        {
            Pen pen = ToPen();
            g.DrawPath(pen, path);
            pen.Dispose();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override Pen ToPen()
        {
            Pen pen = new Pen(_color, (float)_width);
            pen.DashStyle = _dashStyle;
            return pen;            
        }


        


        #endregion

    }
}
